from common.httpRequest import Webrequests


# 商家web端登录
class PublishJob:
    def __init__(self,token,classificationId,title,jobCount,jobDesc,deadline,salaryUnit,salaryTimeUnit,bonus,areaId,addressBuilding,contactNo,heightRequire,deviceId='2505097183',appKey='QTSHE_WEB',sign='68229db7c6fbae9de58641086d0a2bd7',version='4.7.0',timestamp='1550543596932',welfare='包住宿',clearingForm='3',publishTownId='0',addressDetail='不限工作地点',longitude='0',latitude='0',cycleType=2,jobDate='不限工作日期',jobTime="不限工作时间",sexRequire='0',needHeight='false',needHealth='0',diploma='0',contacter='测试12222222222',contactMobile='12222222222',contactWay='0',smsInform='true',openGroupChat='true',deadlineCycle='2'):
        self.token = token
        self.classificationId = classificationId #兼职岗位分类
        self.title = title #兼职标题
        self.jobCount =jobCount #扩展报名人数
        self.jobDesc = jobDesc  #兼职描述
        self.deadline = deadline #报名截止日期
        self.salaryUnit = salaryUnit #单位薪资（**元）
        self.salaryTimeUnit = salaryTimeUnit #薪资单位(1:小时 2:天 3:周 4:月 5:次 0:其他)
        self.bonus = bonus #提成,可不填
        self.areaId = areaId #发布地区ID
        self.addressBuilding = addressBuilding #定位地址（门牌号/几号楼等）,可不填
        self.contactNo = contactNo #工作联系方式 5.7新增
        self.heightRequire = heightRequire #身高要求内容,需要身高要求是必填
        self.deviceId = deviceId
        self.appKey = appKey
        self.sign = sign
        self.version = version #版本号
        self.timestamp = timestamp #时间戳
        self.welfare = welfare #福利,可不填
        self.clearingForm = clearingForm #结算方式
        self.publishTownId = publishTownId #发布城市ID, 0代表全国
        self.addressDetail = addressDetail #详细地址
        self.longitude =longitude #经度,可不填
        self.latitude = latitude
        self.cycleType = cycleType #工作周期(1:短期兼职 2:长期兼职)
        self.jobDate = jobDate #工作日期（如:2015-07-25,2015-07-26;长期兼职工作日期不规范）
        self.jobTime = jobTime
        self.sexRequire = sexRequire #性别要求(0:不限 1:男 2:女) 必填
        self.needHeight = needHeight #身高要求(0:无要求 1：要求)
        self.needHealth = needHealth #健康证要求(false:无要求 true：要求)
        self.diploma = diploma #学历要求:0=不限 2=高中 3=大专 4=本科 6=硕士 7=博士 必填 app中的最低学历
        self.contacter = contacter #联系人
        self.contactMobile = contactMobile #联系人电话
        self.contactWay = contactWay #工作联系类型 1：QQ，2：微信，3：QQ群，4：公众号 5.7新增
        self.smsInform = smsInform #商家是否接收学生报名短信(false:否 true:是)
        self.openGroupChat = openGroupChat #是否开启群聊(false:否 true:是)
        self.deadlineCycle = deadlineCycle #招聘周期 1=短期招聘 2=长期招聘 5.7新增



    def do_publish_job(self):
        url = "https://test-api.qtshe.com:443/jobCenter/companyWeb/partJob/publish"
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        param = {\
        'deviceId':str(self.deviceId),\
        'appKey':str(self.appKey),\
        'sign':str(self.sign),\
        'version':str(self.version),\
        'timestamp':str(self.timestamp),\
        'token':str(self.token),\
        'classificationId':str(self.classificationId),\
        'title':str(self.title),\
        'jobCount':str(self.jobCount),\
        'jobDesc':str(self.jobDesc),\
        'deadline':str(self.deadline),\
        'salaryUnit':str(self.salaryUnit),\
        'salaryTimeUnit':str(self.salaryTimeUnit),\
        'bonus':str(self.bonus),\
        'welfare':str(self.welfare),\
        'clearingForm':str(self.clearingForm),\
        'publishTownId':str(self.publishTownId),\
        'areaId':str(self.areaId),\
        'addressDetail':str(self.addressDetail),\
        'addressBuilding':str(self.addressBuilding),\
        'longitude':str(self.longitude),\
        'latitude':str(self.latitude),\
        'cycleType':str(self.cycleType),\
        'jobDate':str(self.jobDate),\
        'jobTime':str(self.jobTime),\
        'sexRequire':str(self.sexRequire),\
        'needHeight':str(self.needHeight),\
        'heightRequire':str(self.heightRequire),\
        'needHealth':str(self.needHealth),\
        'diploma':str(self.diploma),\
        'contacter':str(self.contacter),\
        'contactMobile':str(self.contactMobile),\
        'contactWay':str(self.contactWay),\
        'contactNo':str(self.contactNo),\
        'smsInform':str(self.smsInform),\
        'openGroupChat':str(self.openGroupChat),\
        'deadlineCycle':str(self.deadlineCycle),\
        }

        try:
           r = Webrequests(url, param, headers).post()
           if r.status_code == 200:
               print("登录成功")
               print("参数:"+str(param))
               return r
        except Exception as e:
            print("登录失败")


